// 引入路由组件
// import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'

// 路由懒加载(导入)
// const foo=()=>{
//     // 只有调用home页面1时候才会执行
//     console.log("home懒加载")
//     return import('@/pages/Home')
// }
export default[
    {
        path:'/center',
        component: Center,
        meta:{show:true},
        children:[
            {
                path:"myOrder",
                component:MyOrder,
            },
            {
                path:"groupOrder",
                component:GroupOrder
            },
            {
                path:"/center",
                redirect:"/center/myOrder"
            }
        ]
    },
    {
        path:'/paySuccess',
        component: PaySuccess,
        meta:{show:true},
    },
    {
        path:'/pay',
        component: Pay,
        meta:{show:true},
        beforeEnter:(to,from,next)=>{
            if(from.path=='/trade'){
                next()
            }else{
                next(false)
            }
        }
    },
    {
        path:'/trade',
        component: Trade,
        meta:{show:true},
        // 路由独享守卫
        beforeEnter:(to,from,next)=>{
            // 只有从购物车来的路由才能跳转到交易页面
            if(from.path=='/shopCart'){
                next()
            }else{
                // 其他的路由组件而来，停留在当前路由
                next(false)
            }
        }
    },
    {
        path:'/shopCart',
        component: ShopCart,
        meta:{show:true},
    },
    {
        path:'/addCartSuccess',
        name:'addCartSuccess',
        component: AddCartSuccess,
        meta:{show:true},
    },
    {
        path:'/detail/:skuid',
        component: Detail,
        meta:{show:true},
    },
    {
        path:'/home',
        component: ()=>import('@/pages/Home'),
        meta:{show:true},
    },
    {
        path:'/login',
        component: Login,
        meta:{show:false},
    },
    {
        path:'/register',
        component: Register,
        meta:{show:false},
    },
    {
        // params 后面加一个问号 代表params参数可传可不传
        path:'/search/:keyword?',
        component: Search,
        meta:{show:true},
        name:"search",
        // 路由组件能不能传递props参数
        // 第一种
        // 布尔值写法
        // 结果是可以把params参数作为路由身上的属性
        // props:true
        // 第二种 对象写法,额外的给路由组件传递一些props
        // props:{a:1,b:2},
        // 对象写法
        props:($route)=>{
            // 需要在组件的props中接收
            return {keyword:$route.params,k:$route.query.k}
        }
    },
    // 重定向，在项目跑起来的时候，访问/ ，立马让他定向到首页
    {
        path:'*',
        redirect:"/home"
    }
]